if the short name of this bg is not "the collection" then
go bg "the collection"
end if
set the name of bg btn id 353 to "List Name:" && activeListName
end showListName
on goListStack thisCard
--Takes you to the list stack, or returns "no" if this is unsuccesful.
--thisCard, the name of the card in the list stack
--you want to go to. is optional.
global listStack
lock screen
set lockMessages to true
set lockRecent to true
go stack listStack
if the short name of this stack <> listStack then exit to hypercard
if cantModify of this stack then
dialogIt "The stack" && quote & listStack & quote && "is locked." && "You can't save changes to your lists until you unlock" && "the stack" && quote & listStack & quote & "."
return "no"
end if
if thisCard is not empty then go cd thisCard
if the result is not empty then
--this card wasn't found
dialogIt "The card" && thisCard && "was not found in" && "the stack" && listStack && "."
return "no"
end if
end goListStack
--LIST scripts
on deleteListEntries whichField
set cursor to arrow
lock screen
send "deleteEntryVisible true" to this cd
put the rect of the name of whichField into listRect
put listRect into validArea
subtract 17 from item 3 of validArea
--17 is the width of the scroll bar
unlock screen with barn door open
repeat
wait while the mouse is up
--the user clicked the mouse
put the clickLoc into userLoc
if userLoc is within the rect of (the name of whichField) AND userLoc is not within validArea then
--user clicked on the scroll bar
next repeat
end if
if userLoc is NOT within validArea OR (the name of whichField) = empty then exit repeat
put clickLine(the name of whichField) into whatLine
if line whatLine of (the value of whichField) = empty then
exit repeat
end if
if isEvenNumber(whatLine) then subtract 1 from whatLine
repeat 2 times
send "selectLine whatLine, the short name of whichField" to this cd
do "delete line whatLine of" && the name of whichField
end repeat
reNumberSequence whatLine,whichField
set cursor to arrow
end repeat
send "deleteEntryVisible false" to this cd
end deleteListEntries
on reNumberSequence N,whichField
--N is the line number of the first line that needs a new entry number
global entryPrefix, entrySuffix
put the value of whichField into thisField
repeat until line N of thisField = empty
set cursor to watch
delete char 1 to the number of chars in entryPrefix of line N of thisField
put (N / 2 + .5) into newNumber
put beginEntryLine(newNumber) into beginLine
put beginLine & newNumber & entrySuffix before line N of thisField
do "put thisField into" && the name of whichField
add 2 to N
end repeat
end reNumberSequence
on findEntry whichLine,findThis,whichField
global listScroll,entryPrefix
if findThis is empty then exit findEntry
if (whichLine/2) = trunc(whichLine/2) then
-- user selected a file name
put line whichLine of the value of whichField into uniqueNumber
else
-- user selected a name
put line (whichLine+1) of the value of whichField into uniqueNumber
end if
-- get rid of extra characters
delete char 1 to (the number of chars in entryPrefix) of uniqueNumber
if the short name of this bg is not "the collection" then
go bg "the collection"
end if
find whole uniqueNumber in fld "file name field"
if the foundText is empty then
dialogIt "In this stack, there isn’t a graphic with the file name" && quote & uniqueNumber & quote & "."
exit findEntry
end if
set scroll of fld "list" to listScroll
unlock screen with visual effect wipe left
end findEntry
on saveChanges dialogNeeded,toBeSaved,savingOpenList
global activeListName,changesToList,taggedList
--dialogNeeded = true if a dialog is needed asking the user
--if they want to save changes.
--savingOpenList = false if you are saving a list that is not
--the active list (as you can do on the Focus card).
-- Return true if the save was completed and succesfully.
-- Otherwise, it return false.
put the long name of this cd into afterSaveGoHere
if savingOpenList then
if changesToList is not true then return false
--the exit was made because a save was unnecessary.
if dialogNeeded then
-- The user needs to be asked if they want to save changes.
dialogIt "Save changes to the list " & quote & activeListName & quote & "?", "No,Yes"
if the result is "No" then
-- The user doesn't want to save the current list.
put "Untitled" into activeListName
put false into changesToList
put empty into taggedList
exit saveChanges
end if
end if
end if
if activeListName is "untitled" OR activeListName is empty then
--Get a name for the list
checkListName "Save the list as (15 letters or less):"
if the result is not empty then return false
--you are at the new list card.
end if
goListStack activeListName
if the result is "no" then
go afterSaveGoHere
return false
end if
set cursor to busy
put toBeSaved into fld "tagged list"
go afterSaveGoHere
set cursor to busy
if savingOpenList then
put false into changesToList
showListName
end if
return true
end saveChanges
on checkListName prompt,default
-- If list entered is invalid, return a non-empty value.
global activeListName
if default = "untitled" then put empty into default
ask prompt with default
put it into whichName
if whichName = empty then return "1"
else if not validListName(whichName) then
checkListName prompt,default
exit checkListName
end if
-- You're in the list stack.
put whichName into activeListName
go last cd of this bg
doMenu "new card"
set the name of this cd to activeListName
end checkListName
on dialogIt whichText, whichButtons, whichFont, whichIcon
if whichButtons is empty then put "OK" into whichButtons
if whichIcon is empty then put "0" into whichIcon
if whichFont is empty then put "chicago" into whichFont
get dialog(whichText,whichButtons,whichIcon,whichFont,plain,12)
return it
end dialogIt
--• THESE SCRIPTS USE THE POINTERS TO FIND SPECIFIC CARDS.
on findAGS dialogPhrase,indexField,pointerField,writeField,goForward
global findParams,lastFindTerms
if the number of lines in lastFindTerms > 1 then
put getCardIdIntersection(lastFindTerms,pointerField,writeField) into validFileNames
else
put getValidFileNames(lastFindTerms,pointerField,writeField) into validFileNames
end if
put binaryInsert(bg fld "file name field",validFileNames) into thisItem
-- thisItem is the item number in validFileNames of the NEXT valid
-- file name in the stack.
put allFoundPrefix(lastFindTerms,dialogPhrase) into allFound
put noneFoundPrefix(lastFindTerms,dialogPhrase) into noneFound
if thisItem = 0 then
dialogIt noneFound
exit findAGS
end if
if not goForward then
put advanceItem(thisItem,goForward,validFileNames) into thisItem
end if
lock screen
repeat with N = (the number of items in validFileNames) down to 1
if the mouseClick then exit repeat
put getCardId(item thisItem of validFileNames) into thisCardId
if thisCardId is empty then exit repeat
go cd id thisCardId
if the result is not empty then next repeat
if the number of lines in lastFindTerms = 1 then
put getLine(lastFindTerms,bg fld indexField) into thisLine
if thisLine is empty then next repeat
end if
-- There is an exact match.
updateStatus N
stopBtnStatus true
if goForward then unlock screen with visual effect wipe left
else unlock screen with visual effect wipe right
if the number of lines in lastFindTerms = 1 then
selectLine thisLine,indexField
end if
if N <> the number of items in validFileNames then
-- This is not the first time through
if shallWeStop() then exit repeat
end if
lock screen
put empty into fld "Status"
put advanceItem(thisItem,goForward,validFileNames) into thisItem
if N = 1 then
-- You've gone to all of the appropriate cards, so stop.
wait 30
stopBtnStatus false
unlock screen
wait 40
if not the mouseClick then dialogIt allFound
end if
end repeat
put the params into findParams
stopBtnStatus false
put empty into bg fld "status"
end findAGS
on updateStatus cardsLeft
if cardsLeft = 1 then put "occurrence" into phrase
else put "occurrences" into phrase
put cardsLeft && phrase && "left. Click and Hold to Stop." into fld "status"
end updateStatus
--• THESE SCRIPTS HANDLE THE POINTERS.
on buildPointers indexField,writeField,pointerField
put readIndex(writeField) into thisIndex
put the number of lines in thisIndex into numberOfEntries
set cursor to watch
lock screen
set lockMessages to true
put "Building pointers for" && writeField into status
if whichText = empty OR whichText = space then next repeat
go cd 1 of bg "the collection"
put empty into entries
put empty into firstCard
put empty into currentCard
repeat
find whole whichText in fld indexField
if the foundChunk is empty then
--The text wasn't found in the specified field.
exit repeat
end if
put word 2 of the foundLine into thisLine
if whichText <> line thisLine of fld indexField then
--There was a find, but not an exact match, so look again.
next repeat
end if
if firstCard = empty then
put the short id of this cd into firstCard
else put the short id of this cd into currentCard
if firstCard = currentCard then
--you've been to all of the valid cards.
exit repeat
end if
--If it got this far, then there was an exact match.
put bg fld "file name field" & "," after entries
end repeat
put the number of chars in whichText into fldNumber
put last char of fldNumber into fldNumber
if last char of entries is "," then delete last char of entries
writePointer entries,N,pointerField && fldNumber
end repeat
hideProgress
end buildPointers
on writePointer newPointer,lineNumber,fldName
put newPointer into line lineNumber of cd fld fldName of cd "Index storage"
end writePointer
--•• END AGS ONLY
--•• FUNCTIONS
function diskSpaceAvailable
-- Return true if the disk space available is greater than the
-- limit given. Otherwise, return false.
if the diskSpace > 5000 then return true
put the long name of this stack into stackName
delete char 1 to 7 of stackName
delete last char of stackName
put volumeName(stackName) into diskName
put round(the diskSpace / 1000) into spaceAvailable
dialogIt "There is" && spaceAvailable & "K of disk space" && "available on" && quote & diskName & quote & ". Since this may" && "not be enough disk space to continue, the current task has been" && "stopped. You should move this stack to a disk with more" && "space available before continuing this task."
return false
end diskSpaceAvailable
function isWithin thisText, container
-- Return true of thisText is a complete line in the given container.
if line 1 of container = thisText OR container contains return & thisText & return OR thisText = last line of container then return true
return false
end isWithin
function clickLine whichField
-- Return the number of the line clicked.
-- First, determine how many lines are hidden above
if the style of whichField is "scrolling" then
put the scroll of whichField into theScroll
else put 0 into theScroll
put (theScroll / textHeight of whichField) into linesAbove
-- add that number to the relative position clicked